package com.yiwenup.leetcode.site;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.site
 * @Author yiwenup
 * @Date 2024-12-08 17:18:34
 * @Description https://leetcode.cn/problems/minimum-size-subarray-sum/description/
 */
public class No0209 {
    public int minSubArrayLen(int target, int[] nums) {
        int sum = 0;
        int left = 0;
        int ans = Integer.MAX_VALUE;
        for(int right = 0; right < nums.length; right++) {
            sum += nums[right];
            while(sum >= target) {
                ans = Math.min(ans, right - left + 1);
                sum -= nums[left++];
            }
        }
        return ans == Integer.MAX_VALUE ? 0 : ans;
    }
}
